package galnaat.szofttech;

import java.util.Random;

public class fight {
	boolean result = false;
	String log = "";
	
    private static int te, ve, hp;

    private static final int delta = 8;
    Random generator = new Random();
    
	public fight(player p) {
		// Build up the monster
        te = 25 + generator.nextInt( delta ) - delta / 2;
        ve = 15 + generator.nextInt( delta ) - delta / 2;
        hp = 20 + generator.nextInt( delta );
        log += "Felelmetes szornyel talalkoztal!\n";
        log += "te: "+ String.valueOf(te) +" ve: "+ String.valueOf(ve) +" hp: "+ String.valueOf(hp) +"\n";
        // Fight
        int r, i;
        while (p.alive() && hp >= 0) {
        	// Turn
        	r = generator.nextInt( delta );
        	if (r <= p.te()-ve) {
        		i = generator.nextInt(10);
        		hp -= i;
                log += "Eltalaltad, serult "+ String.valueOf(i) +" hpt!\n";
        	} else {
        		log += "Sajnos melle\n";
        	}
        	r = generator.nextInt( delta );
        	if (hp >= 0 && r <= p.ve()-te) {
        		i = generator.nextInt(10);
        		p.blood(i);
                log += "A szorny megsebzet, vesztettel "+ String.valueOf(i) +" hpt!\n";
        	} else {
        		log += "A szorny megbotlott\n";
        	}
        }
        // Valaki halott
        if (hp <= 0) {
        	log += "A szorny meghalt, kaptal "+ String.valueOf(te+ve) +"XPt\n";
        	p.experience(te+ve);
        	result = true;
        } else {
        	log += "Ez most nem jott ossze, kalandozasod veget ert!\n";
            result = false;
        }
	}
	
	public boolean getResult() {
		return result;
	}
	
	public String getLog() {
		return log;
	}
}
